<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    // 字面量
    let emp = {
      name: "程斌",
      age: 20,
      get info () {
        return this.name + this.age;
      }
    }

    let handler = {
      //获取
      get: function (target, key) {
        console.log('获取对象的值过滤操作', target[key]);

        // return target[key];
        return Reflect.get(target, key);
      },
      //设置
      set: function (target, key, value) {
        console.log('设置对象的键和值');
        // target[key] = value;
        Reflect.set(target, key, value);
      }
    }


    let proxy = new Proxy(emp, handler)
    proxy.age = 22;
    console.log(proxy.age);


    // console.log(emp.name);
    // console.log(emp['name']);

    // emp.name = '张三';

    // let x = Reflect.get(emp, 'name')
    // console.log(x);

    // let receiver = {
    //   name: "wangshuai",
    //   age: 22,
    //   sex: '男'
    // }

    // // this: emp,   this: receiver
    // x = Reflect.get(emp, 'info', receiver)

    // console.log(emp);
    // console.log(x);
    // console.log(receiver);





  </script>
</body>

</html>